package org.wmq.skyserver.controller.admin;

import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.wmq.skycommon.pojo.DTO.EmployeeDTO;
import org.wmq.skycommon.pojo.DTO.EmployeePageQueryDTO;
import org.wmq.skycommon.pojo.entity.Result;
import org.wmq.skyserver.service.EmployeeService;

@Slf4j
@RestController
@RequestMapping("/admin/employee")
public class EmployeeController {
    @Autowired
    private EmployeeService employeeService;

    @PostMapping
    @ApiOperation("新增员工")
    public Result save(@RequestBody EmployeeDTO employeeDTO) {
        this.employeeService.save(employeeDTO);
        return Result.success();
    }

    @GetMapping("/page")
    @ApiOperation("员工分页查询")
    public Result page(@ModelAttribute EmployeePageQueryDTO employeePageQueryDTO) {
        return Result.success(this.employeeService.pageQuery(employeePageQueryDTO));
    }

    @PostMapping("/status/{status}")
    @ApiOperation("启用禁用员工账号")
    public Result startOrStop(@PathVariable Integer status,Long id){
        this.employeeService.startOrStop(status,id);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getById(@PathVariable Long id) {
        return Result.success(this.employeeService.getById(id));
    }

    @PutMapping
    @ApiOperation("编辑员工信息")
    public Result update(@RequestBody EmployeeDTO employeeDTO) {
        this.employeeService.update(employeeDTO);
        return Result.success();
    }

}
